﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace GeneralDFS.DataEntity.IO
{
    [Serializable]
    public class FileBlockQueue<T>
    {
        private volatile Queue<T> _queue=new Queue<T>(); 

        public int Size()
        {
            lock (_queue)
            {
                return _queue.Count;
            }
        }

        public void Enqueue(T newNode)
        {
            lock (_queue)
            {
                _queue.Enqueue(newNode);
            }
        }

        public T Dequeue()
        {
            lock (_queue)
            {
                return _queue.Dequeue();
            }
        }

        public void Clear()
        {
            lock (_queue)
            {
                _queue.Clear();
            }
        }

        public Boolean Contains(T node)
        {
            return _queue.Contains(node);
        }

        public List<T> Poll(int num)
        {
            if (_queue.Count == 0) return null;
            var newList=new List<T>();
            for (var i = 0; i < num; i++)
            {
                newList.Add(Dequeue());
            }
            return newList;
        }
    }
}
